<!DOCTYPE html>
<html>
<head>@ include("/weixin/include/header.html",{"title":"发送通知"}){}
</head>
<body >
	<form id="form1" method="post" action="${basePath}/weixinNotice/doSend" >
	<input type="hidden" name="uId" value="2075">
	<input type="hidden" name="teaIds" id="teaIds" value="">	
	<input type="hidden" name="parIds" id="parIds" value="">	
	<input type="hidden" name="stuIds" id="stuIds" value="">	
	<div class="weui_cells weui_cells_form" style="margin-top: 14px;">
		<div class="weui_cell">
			<div class="weui_cell_bd weui_cell_primary">
				<input class="weui_input" type="tel" name="title" placeholder="请输入通知标题">
			</div>
		</div>
	</div>
	<div class="weui_cells weui_cells_form" style="margin-top: 14px;">
		<div class="weui_cell" style="margin-top: 14px;">
			<div class="weui_cell_bd weui_cell_primary">
				<textarea class="weui_textarea" placeholder="请输入通知内容" rows="4" name="content"></textarea>
			</div>
		</div>
	</div>
	</form>
	<div class="tree" style="margin-top: 14px" id = "tree">
		
	</div>
	
	
	
	<a href="javascript:submit();" class="weui_btn weui_btn_primary"
		style="margin: 16px;">发送通知</a>
		 @	include("/weixin/include/js_import.html"){}
	<script type="text/javascript">
		var nodeData = [
						
@  for(node in nodeList){
					{"id":"${node.id}","name":"${node.name}","pid":["${node.pid}"],"type":"${node.type}"},
@  }
		];
	
		$(function() {
			initNodes();
		});
		
		function aClick(icon,e){
			if(e != undefined){
				e.stopPropagation();
			}
			var item = $(icon).parent();
			if(item.hasClass("active")){
				item.removeClass("active");
				checkSubs(item,false);
				
			}else{
				item.addClass("active");
				checkSubs(item,true);
				
			}
			
		}
		
		function checkSubs(itemDiv, isChecked){
			if(isChecked){
				itemDiv.siblings().find(".item").addClass("active");
			}else{
				itemDiv.siblings().find(".item").removeClass("active");				
			}
		}
		
		
		function rowClick(div,e){
			e.stopPropagation();
			$(div).siblings().toggle();
		}
		
		function initNodes(){
			var tree = $("#tree");
			for(var i in nodeData){
				var item = nodeData[i];
				if(item.type == 't'){
					tree.append("<div class='row' id='"+item.type+"_"+item.id+"'><div class='item tea' data='"+item.type+"_"+item.id+"'  onclick='rowClick(this,event)'><a onclick='aClick(this,event)'></a><span>"+item.name+"</span></div></div>");
				
				}else if(item.type=="d1"){
					tree.append("<div class='row' id='"+item.type+"_"+item.id+"'><div class='item'  onclick='rowClick(this,event)'><a onclick='aClick(this,event)'></a><span>"+item.name+"</span></div></div>");
							
				}else if(item.type=="d2"){
					tree.append("<div class='row' id='"+item.type+"_"+item.id+"'><div class='item par' data='"+item.type+"_"+item.id+"'  onclick='rowClick(this,event)'><a onclick='aClick(this,event)'></a><span>"+item.name+"</span></div></div>");
							
				}else if(item.type=="d3"){
					tree.append("<div class='row' id='"+item.type+"_"+item.id+"'><div class='item stu' data='"+item.type+"_"+item.id+"'  onclick='rowClick(this,event)'><a onclick='aClick(this,event)'></a><span>"+item.name+"</span></div></div>");
							
				}				
			}
			
			for(var i in nodeData){
				var item = nodeData[i];
				var pidArray =(""+item.pid).split(",");
				for(var j in pidArray){
					moveTo(item.id,item.type,pidArray[j]);
				}
			}			
		}
		
		function submit(){
			var str = getSelectedIds();
			
			form1.submit();
		}
		
		function getSelectedIds(){
			var str = "";
			$(".par.active").each(function(index,element){
				str = str+","+$(element).attr("data");
			});
			$("#parIds").val(str);
			str = "";
			$(".stu.active").each(function(index,element){
				str = str+","+$(element).attr("data");
			});
			$("#stuIds").val(str);
			str = "";
			var temp={};
			$(".tea.active").each(function(index,element){
				var id = $(element).attr("data");
				if(!temp[id]){
					temp[id] = 1;
					str = str+","+$(element).attr("data");
				}
				
			});
			$("#teaIds").val(str);
			console.log(str);
			return str;
		}
		
		function moveTo(id,type,pid){
			pid = "d1_"+pid;
			if($("#"+pid)){
				if($("#"+type+"_"+id).parent().attr("id")=="tree"){
					$("#"+type+"_"+id).appendTo($("#"+pid));
				}else{
					$("#"+type+"_"+id).clone().appendTo($("#"+pid));
				}
			}
		}
	
	</script>
</body>
</html>